package com.imooc.spark

import org.apache.spark.sql.SparkSession

/**
 * Dataset操作
 */
object DatasetApp {

  def main(args: Array[String]) {
    val spark = SparkSession
      .builder()
      .appName("DatasetApp")
      .master("local[2]")
      .getOrCreate()

    //注意：需要导入隐式转换
    import spark.implicits._

    val path = "file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\sales.csv"

    //spark如何解析csv文件？
    val df = spark.read.option("header", "true").option("inferSchema", "true").csv(path)
    df.show

    val ds = df.as[Sales]
    ds.map(line => line.itemId).show

    //compile ok. result no
    spark.sql("seletc name from person").show

    //df.seletc("name")  //compile no
    df.select("nname")  //compile ok, result no

    ds.map(line => line.itemId)

    spark.stop()
  }

  case class Sales(transactionId: Int, customerId: Int, itemId: Int, amountPaid: Double)
}
